﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="hrCalcSalary.aspx.cs" Inherits="ZX.WebApp.EHR.hrCalcSalary" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <style type="text/css">
      body
      { 
          font-family: 宋体, Arial, Helvetica, sans-serif;
          font-size: 12px;
      } 
      td
      {
          text-align:left;
      }
    </style>
    <script src="../Scripts/jquery-1.6.min.js" type="text/javascript"></script>
    <script type="text/javascript" src="../Scripts/yui_2.9.0/build/yahoo-dom-event/yahoo-dom-event.js"></script>
    <script type="text/javascript" src="../Scripts/yui_2.9.0/build/json/json-min.js"></script>
    <script type="text/javascript" src="../Scripts/yui_2.9.0/build/connection/connection-min.js"></script>
    <script src="../Scripts/Public.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            var date = new Date();
            var year = date.getYear();
            var flag = getPar1("flag");
            var obj = null;
            if (flag == "1") {
                obj = $("#cbDeptYearMonth")
            }
            else {
                obj = $("#cbYearMonth")
            }
            for (var i = 1; i < 13; i++) {
                var month = i;
                if (i < 10) month = "0" + i;
                obj.append("<option value='" + (year-1) + "-" + month + "' title='" + (year-1) + "-" + month + "'>" + (year-1) + "-" + month + "</option>");
            }
            for (var i = 1; i < 13; i++) {
                var month = i;
                if (i < 10) month = "0" + i;
                obj.append("<option value='" + year + "-" + month + "' title='" + year + "-" + month + "'>" + year + "-" + month + "</option>");
            }
            if (flag == "1") { //计算部门薪资界面
                $("#divDept").show();
                $("#divEmp").hide();
                var deptName = getPar(decodeURI(location.href), "deptName");
                var deptId = getPar(decodeURI(location.href), "deptId");
                $("#txtDeptName").val(deptName);
                $("#deptId").val(deptId);
                parent.$("#yui-gen0-button").bind("click", calcSalary);
            }
            else { //计算员工薪资界面
                $("#divDept").hide();
                $("#divEmp").show();
                $("#txtEmpCode").change(function () {
                    $("#deptName").val("");
                    $("#postName").val("");
                    $("#txtEmpName").val("");
                    $("#EmployeeID").val("");
                    var empcode = $("#txtEmpCode").val();
                    if (empcode == "") return;
                    var url = "../Extend/AjaxData/jsonlist.aspx?entity=V_hrEmployee&condition=EmployeeCode='" + empcode + "'&r=" + Math.random();
                    $.get(url, function (d, s) {
                        var list = eval("(" + d + ")");
                        if (list.total > 0) {
                            for (var o in list.rows) {
                                var empId = list.rows[o].ID;
                                var empName = list.rows[o].CName;
                                var dept = list.rows[o].DeptName;
                                var post = list.rows[o].PostName;
                                if (typeof (empId) != "undefined") {
                                    $("#deptName").val(dept);
                                    $("#postName").val(post);
                                    $("#txtEmpName").val(empName);
                                    $("#EmployeeID").val(empId);
                                    parent.$("#yui-gen0-button").bind("click", calcSalary);
                                    break;
                                }
                            }
                        }
                    });
                });
            }
        });

        //计算薪资
        function calcSalary() {
            var flag = getPar1("flag");
            var url = "";
            $("#divTip").show();
            if (flag == "1") {
                var deptId = $("#deptId").val();
                var yearMonth = $("#cbDeptYearMonth").val();
                url = "hrSalaryAjax.aspx?flag=calcDeptSalary&deptId=" + deptId + "&yearMonth=" + yearMonth + "&r=" + Math.random();
                if (deptId == "") {
                    alert("部门错误!");
                    return;
                }
                if (yearMonth == "") {
                    alert("请选择计算年月!");
                    return;
                }
                $("#divDept").attr("disable", true);
            }
            else {
                var empId = $("#EmployeeID").val();
                var yearMonth = $("#cbYearMonth").val();
                url = "hrSalaryAjax.aspx?flag=calcEmpSalary&empId=" + empId + "&yearMonth=" + yearMonth + "&r=" + Math.random();
                if (empId == "") {
                    alert("请输入正确的员工编号!");
                    return;
                }
                if (yearMonth == "") {
                    alert("请选择计算年月!");
                    return;
                }
                $("#divEmp").attr("disable", true);
            }
            parent.$("#yui-gen0-button").hide();
            YAHOO.util.Connect.asyncRequest('POST', url, {
                success: function (res) {
                    try {
                        var str = res.responseText;
                        if (str == "0") {
                            $("#divTip").hide();
                            alert("计算完成!");
                            parent.$("#yui-gen0-button").unbind("click", calcSalary);
                            parent.$("#yui-gen0-button").show();
                            parent.closeWin();
                        }
                        else {
                            parent.$("#yui-gen0-button").show();
                            $("#divTip").hide();
                            alert("计算失败");
                        }
                    }
                    catch (e) {
                    }
                    finally {
                    }
                },
                failure: function (error) {
                    $("#divTip").hide();
                    parent.$("#yui-gen0-button").show();
                    alert("数据错误：" + error.statusText);
                }
            }, null);
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <br />
    <input type="hidden" id="EmployeeID" />
    <input type="hidden" id="deptId" />
    <div id="divEmp" align="center">
       <table>
         <tr>
           <td>
              员工编号:
           </td>
           <td>
              <input type="text" id="txtEmpCode" style="width:200px" />
           </td>
         </tr>
         <tr>
           <td>
              计算年月:
           </td>
           <td>
              <select id="cbYearMonth" style="width:206px" ></select>
           </td>
         </tr>
         <tr>
           <td>
              员工姓名:
           </td>
           <td>
              <input type="text" id="txtEmpName" style="background-color:whitesmoke;width:200px;" readonly="readonly" />
           </td>
         </tr>
         <tr>
           <td>
              所属部门:
           </td>
           <td>
              <input type="text" id="deptName" style="background-color:whitesmoke;width:200px;" readonly="readonly" />
           </td>
         </tr>
         <tr>
           <td>
              所在岗位:
           </td>
           <td>
              <input type="text" id="postName" style="background-color:whitesmoke;width:200px;" readonly="readonly" />
           </td>
         </tr>
       </table>
    </div>
    <div id="divDept" align="center">
       <table>
       <tr>
           <td>
              部门名称:
           </td>
           <td>
              <input type="text" id="txtDeptName" style="width:200px" />
           </td>
         </tr>
         <tr>
           <td>
              计算年月:
           </td>
           <td>
              <select id="cbDeptYearMonth" style="width:206px" ></select>
           </td>
         </tr>
       </table>
    </div>
    <br />
    <div id="divTip" style="display:none"><span style="color:Red;font-family: 宋体, Arial, Helvetica, sans-serif;font-size: 12px;">正在做薪资计算，请稍候...</span></div>
    </form>
</body>
</html>
